﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Db4objects.Db4o;
using Db4objects.Db4o.Linq;
using System.Linq;
using Db4objects.Db4o.Query;
using MonthCalendar;


namespace Yosca
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			//"this" is not technically needed  <<--- InitializeComponent might not be static
			this.InitializeComponent();
			collapseAll();  //collapses all panels
            HC.Visibility = Visibility.Visible;
			SearchControl.populateGrid();
            ExpControl.populateExpenseGrid();
			HC.addAppointmentsToPane();
			// Insert code required on object creation below this point.
			
			//index the fields we want queryable(improves performance dramatically)

		}
		
		private void homeClick(object sender, System.Windows.RoutedEventArgs e)
        {
        	collapseAll();
            HC.addAppointmentsToPane();
            HC.Visibility = Visibility.Visible;
        }

		private void newCustClick(object sender, RoutedEventArgs e)
		{
			collapseAll();
            CustomerControl.Visibility = Visibility.Visible;
			//newCustPanel1.Visibility = Visibility.Visible; //show the new customer panel
		}
		private void searchPanelClick(object sender, System.Windows.RoutedEventArgs e)
		{
			collapseAll();
            SearchControl.Visibility = Visibility.Visible;//show the search panel
            SearchControl.curInv.Visibility = Visibility.Collapsed;
            SearchControl.newInv.Visibility = Visibility.Collapsed;

			
		}
		private void calendarClick(object sender, System.Windows.RoutedEventArgs e)
		{
			collapseAll();
            AppointmentDB adb = AppointmentDB.Instance;
            CalControl.SetAppointments(adb);
            CalControl.Visibility = Visibility.Visible;
		}
		
		void collapseAll()
		{
			//collapse all panels to eliminate any issues with panel overlap
            HC.Visibility = Visibility.Collapsed;
            CustomerControl.Visibility = Visibility.Collapsed;
            SearchControl.Visibility = Visibility.Collapsed;
			CalControl.Visibility = Visibility.Collapsed;
			TimeControl.Visibility = Visibility.Collapsed;
			ExpControl.Visibility = Visibility.Collapsed;
            PayControl.Visibility = Visibility.Collapsed;
			RepControl.Visibility = Visibility.Collapsed;
			ABControl.Visibility = Visibility.Collapsed;
			
		}

		private void ontimecardClick(object sender, System.Windows.RoutedEventArgs e)
		{
			collapseAll();
            TimeControl.Visibility = Visibility.Visible;//  show the time card panel
            TimeControl.workerGrid.IsReadOnly = true;
            //load worker list on panel load
            Database dbase = Database.Instance;
			IEnumerable<Worker> workerList = from Worker w in dbase.db
											 select w;
            if(workerList.ToList() != null)
                TimeControl.workerGrid.ItemsSource = workerList.ToList();
		}

		private void expensesClick(object sender, System.Windows.RoutedEventArgs e)
		{
			collapseAll();
			ExpControl.Visibility = Visibility.Visible;//  view the expenses panel
            ExpControl.expenseGrid.IsReadOnly = true;
            ExpControl.expenseGrid.Columns.Clear();
            ExpControl.populateExpenseGrid();
		}

		private void payrollClick(object sender, System.Windows.RoutedEventArgs e)
		{
			collapseAll();
            PayControl.Visibility = Visibility.Visible;//  view the payroll panel;
		}

		private void reportClick(object sender, System.Windows.RoutedEventArgs e)
		{
			collapseAll();
			RepControl.Visibility = Visibility.Visible;//  view the reports panel
            RepControl.reportGrid.IsReadOnly = true;
            RepControl.reportGrid.CanUserAddRows = false;
		}

		private void aboutClick(object sender, System.Windows.RoutedEventArgs e)
		{
			collapseAll();
			ABControl.Visibility = Visibility.Visible;//  view the about panel
		}

    
        private void AtExit(object sender, System.ComponentModel.CancelEventArgs e)
        {
        	Application.Current.Shutdown();
        }

        private void menuExit(object sender, System.Windows.RoutedEventArgs e)
        {
        	Application.Current.Shutdown();
        }

    }
}
